{extend name="public/base"}

{block name="title"}添加链接{/block}

{block name="main"}
<!--添加用户UI-->
<div class="layui-row">
    <div class="layui-col-md4 layui-col-md-offset4">
        <form action="{:url('/adv')}" method="post" class="layui-form layui-form-pane">


            <div class="layui-form-item" >
                <label for="text" class="layui-form-label">链接</label>
                <div class="layui-input-block">
                    <input type="url"  required   id="text" name="text" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">广告位置</label>
                <div class="layui-input-block">
                    <select name="position" id="position" class="form-control w-50  col-form-label">
                        <option value="1" selected>安卓下载地址</option>
                        <option value="2">苹果下载地址</option>
                        <option value="3">备用下载地址</option>
                        <option value="4">H5地址</option>
                        <option value="5">客服链接</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <a href="{:url('/adv')}" class="layui-btn layui-btn-normal  layui-btn-sm"><i class="layui-icon layui-icon-left"></i>返回列表</a>
            </div>
            <div class="layui-form-item">
                <input type="hidden" value="{:token()}" name="__token__">
                <button class="layui-btn layui-btn-success layui-btn-fluid layui-btn-lg">提交添加</button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['upload','layer','jquery','form'], function(){
        var upload = layui.upload,
        layer = layui.layer,
            $=layui.$;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: "{:url('index/upload')}" //上传接口
            ,field:'image'
            ,accept: 'image'
            ,acceptMime:'image/*'
            ,before:function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
                layer.msg('上传中', {icon: 16, time: 0});
            }
            ,done: function(res){
                //上传完毕回调
                if (res.code===200){
                    layer.msg(res.msg,{
                        icon:1
                    })
                    $('#img').val(res.path)
                }else{
                    layer.msg(res.msg,{
                        icon:2
                    })
                }
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });
</script>
{/block}